package top.lyc829.zzl_android.ui.custom_view;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.xuexiang.xui.widget.imageview.RadiusImageView;

import top.lyc829.zzl_android.R;
import top.lyc829.zzl_android.logic.util.Utils;

public class ProfileCard extends LinearLayout {

    private Context context;
    private float height = 0f;
    private float width = 0f;

    private RadiusImageView headerImage;
    private TextView username;

    private void init() {

        this.setOrientation(LinearLayout.HORIZONTAL);

        headerImage = new RadiusImageView(context);
        username = new TextView(context);
    }


    public ProfileCard(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public ProfileCard(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public ProfileCard(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        // 获取设备宽高
        this.width = w;
        this.height = h;
        Utils.Sout("h:" + h + "w:" + w);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

    }

    public void setHeaderImage(String headerImageUrl) {
        Glide.with(context)
                .load(headerImageUrl)
                .into(headerImage);
        headerImage.setCircle(true);

        LayoutParams params = new LinearLayout.LayoutParams(200, 200);
        headerImage.setLayoutParams(params);

        addView(headerImage);
        invalidate();
    }

    public void setUsername(String username) {
        this.username.setText(username);
        this.username.setTextSize(24);
        this.username.setTextColor(getResources().getColor(R.color.black, null));
        addView(this.username);
        invalidate();
    }
}
